import random

# 扩展后的蔬菜清单
vegetables = [
    "菠菜", "香菜", "芹菜（西芹）", "蕹菜（空心菜）", "茼蒿", "苋菜", "莴苣", "油麦菜",
    "小白菜", "塌棵菜", "菜心（菜薹）", "大白菜", "油菜", "西兰花", "花椰菜", "卷心菜",
    "紫甘蓝", "芥蓝", "西洋菜", "水芹", "大葱", "小葱", "大蒜", "洋葱", "韭菜",
    "芦笋", "黄瓜", "丝瓜", "冬瓜", "苦瓜", "南瓜", "西葫芦", "茄子", "番茄",
    "辣椒", "菜椒", "番薯", "马铃薯", "胡萝卜", "白萝卜", "豌豆", "刀豆",
    "蚕豆", "豇豆", "扁豆", "四季豆", "毛豆", "莲藕", "茭白"
]

# 其他食材
proteins = ["鸡蛋", "猪肉", "牛肉", "鸡胸肉", "虾仁", "鱿鱼"]

# 做法
simple_methods = ["清炒", "凉拌", "清蒸"]
complex_methods = ["爆炒", "红烧", "煮"]

# 不合理组合过滤列表
invalid_combinations = [
    "清蒸洋葱", "凉拌姜", "清蒸白萝卜", "爆炒白萝卜", "清蒸洋葱", "凉拌洋葱",
    "清蒸香菜", "凉拌香菜", "清蒸大蒜", "煮大蒜", "煮洋葱", "凉拌大葱",
    "凉拌油麦菜", "凉拌芹菜（西芹）", "凉拌茼蒿", "凉拌莴苣", "清炒大葱",
    "清蒸姜", "凉拌洋葱", "猪肉炒牛肉", "清蒸猪肉", "清蒸牛肉", "清蒸鸡胸肉"
]


# 合理的组合规则
def generate_dish(vegetable, avoid_methods=None):
    method_pool = simple_methods + complex_methods

    if avoid_methods:
        method_pool = [method for method in method_pool if method not in avoid_methods]

    while True:
        method = random.choice(method_pool)

        # 确保肉类不会被清蒸或凉拌
        if vegetable in proteins and method in ["清蒸", "凉拌"]:
            continue

        if method in ["清炒", "爆炒"]:
            if random.random() > 0.5:
                # 防止肉炒肉的情况
                if vegetable in proteins:
                    continue
                protein = random.choice(proteins)
                dish = f"{vegetable}炒{protein}"
            else:
                dish = f"{method}{vegetable}"
        else:
            dish = f"{method}{vegetable}"

        # 过滤不合理的组合
        if dish not in invalid_combinations:
            break

    return dish, method


# 生成菜单
def generate_menu():
    selected_vegetables = random.sample(vegetables, 4)
    selected_proteins = random.sample(proteins, 2)

    shopping_list = selected_vegetables + selected_proteins

    lunch, lunch_methods = [], []
    dinner, dinner_methods = [], []

    for i in range(1):
        dish, method = generate_dish(selected_vegetables[i], avoid_methods=lunch_methods)
        lunch.append(dish)
        lunch_methods.append(method)

        dish, method = generate_dish(selected_vegetables[i + 2], avoid_methods=dinner_methods)
        dinner.append(dish)
        dinner_methods.append(method)

    for i in range(2):
        dish, method = generate_dish(selected_proteins[i], avoid_methods=lunch_methods + dinner_methods)
        if i == 0:
            lunch.append(dish)
            lunch_methods.append(method)
        else:
            dinner.append(dish)
            dinner_methods.append(method)

    return {"午餐": lunch, "晚餐": dinner}, shopping_list


# 打印菜单和购物清单
def print_menu(menu, shopping_list):
    print("★☆★☆★☆ 今日菜谱 ★☆★☆★☆\n")
    for meal, dishes in menu.items():
        print(f"{meal}：")
        for dish in dishes:
            print(f"  - {dish}")
        print("\n")

    print("★☆★☆★☆ 购物清单 ★☆★☆★☆\n")
    for item in shopping_list:
        print(f"  - {item}")


if __name__ == "__main__":
    menu, shopping_list = generate_menu()
    print_menu(menu, shopping_list)